home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17941 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: news.th-darmstadt.de!news
  2. From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Incompatible function pointers?
  5. Date: Thu, 18 Apr 1996 09:22:27 +0200
  6. Organization: Fachbereich Informatik, TH Darmstadt
  7. Message-ID: <3175EDB3.2781E494@intellektik.informatik.th-darmstadt.de>
  8. References: <4l3fp5INN1ak@sit.sps.mot.com>
  9. NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.01 (X11; I; SunOS 4.1.3 sun4m)
  14.  
  15. Matthew Moss wrote:
  16. > Can anyone tell me why this won't work? All compilers I've tried complain
  17. > about passing G::Create() into test().... I would've thought this a problem
  18. > if they were member functions, but G::Create() is static.
  19. > I couldn't easily find anything about this in the ARM or ANSI references...
  20. > Thanks...
  21. > class A {
  22. > [ ... ]
  23. >  public:
  24. >   static G* Create(A*);
  25. > };
  26. > typedef void* (*CreatorFP)(A*);
  27.  
  28. This should be 'typedef G* (*CreatorFP)(A*)'.
  29.  
  30. > [ ... ]
  31. > void* test(A *a, CreatorFP cfp)
  32. > {
  33. >   return (*cfp)(a);
  34. > }
  35. > void main()
  36. > {
  37. >   A *a = new A(65);
  38. >   G *g = (G*) test(a, G::Create);
  39. >   delete g;
  40. >   delete a;
  41. > }
  42.  
  43.     Enno
  44.